package tag38_02_09.threadsWeiter;

public class Th15_synchMethoden {
	
	//Warum static?, weil man eine Innere class ertellen kann...
		static class Inkrement{ 
			private int count;
			
			void inkrement(){
				synchronized (this) {
					count++;
				}
//				for (int i = 0; i < 10; i++) {
//				}
			}

//			public int getCount() {
//				synchronized (this) {
//					return count;	
//				}
				
//			}
			synchronized public int getCount() {
				return count;
		}
}

	
	
	
	//-------------------------------------------------------
	public static void main(String[] args) throws InterruptedException {

		Inkrement i1 = new Inkrement();
		
		Thread t1 = new Thread(){
			public void run(){
				i1.inkrement(); // i = 9, count = 9 -> cpu 10
				
			}
		};
		
		t1.start();
		
		Inkrement i2 = new Inkrement();
		i2.inkrement();
		
		t1.join();
		
		System.out.println("count: " + i1.getCount());
	}
	
}


